package com.zoweunion.mechanic.controller.base;

import com.alibaba.fastjson.JSONObject;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.model.ResponseBean;
import com.zoweunion.mechanic.model.User;
import com.zoweunion.mechanic.service.base.CarModelManagementService;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.util.constants.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 车型管理
 */
@RestController
@RequestMapping("carModelManagement")
public class CarModelManagementController extends BaseController {

    @Autowired
    private CarModelManagementService carModelManagementService;


    /**
     * 车型管理 列表页面
     *
     * @param str
     * @returngetCarType
     */
    @PostMapping("/list")
    public ResponseBean list(@RequestBody String str, HttpServletRequest request) throws MyException {
        logBefore(logger, "车型管理 列表页面");
        User currentUser = getCurrentUser(request);
        Map<String, Object> reqMap = JSONObject.parseObject(str, JSONObject.class);
        Map<String, Object> resultMap = carModelManagementService.list(currentUser, reqMap);
        logAfter(logger);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", resultMap);
    }

    /**
     * 车型管理 保存接口
     *
     * @param str
     * @returngetCarType
     */
    @PostMapping("/save")
    public ResponseBean save(@RequestBody String str, HttpServletRequest request) throws MyException {
        logBefore(logger, "车型管理 保存接口");
        User currentUser = getCurrentUser(request);
        Map<String, Object> reqMap = JSONObject.parseObject(str, JSONObject.class);
        boolean result = carModelManagementService.save(currentUser, reqMap);
        logAfter(logger);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", result);
    }

    /**
     * 车型管理 获取详情
     *
     * @param str
     * @returngetCarType
     */
    @PostMapping("/detail")
    public ResponseBean detail(@RequestBody String str, HttpServletRequest request) throws MyException {
        logBefore(logger, "车型管理 获取详情");
        User currentUser = getCurrentUser(request);
        Map<String, Object> reqMap = JSONObject.parseObject(str, JSONObject.class);
        Map<String, Object> result = carModelManagementService.detail(currentUser, reqMap);
        logAfter(logger);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", result);
    }

    /**
     * 车型管理 删除接口
     *
     * @param str
     * @returngetCarType
     */
    @PostMapping("/delete")
    public ResponseBean delete(@RequestBody String str, HttpServletRequest request) throws MyException {
        logBefore(logger, "车型管理 删除接口");
        User currentUser = getCurrentUser(request);
        Map<String, Object> reqMap = JSONObject.parseObject(str, JSONObject.class);
        boolean result = carModelManagementService.delete(currentUser, reqMap);
        logAfter(logger);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", result);
    }

    /**
     * 查看车型是否设置油箱
     */
    @GetMapping("/selectFuelTank")
    public ResponseBean selectFuelTank(@RequestParam Map<String,Object> map, HttpServletRequest request) throws MyException {
        Map<String, Object> map1 = carModelManagementService.selectFuelTank(map);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", map1);
    }

    /**
     * 车型设置油箱
     */
    @GetMapping("/updateFuelTank")
    public ResponseBean updateFuelTank(@RequestParam Map<String,Object> map, HttpServletRequest request) throws MyException {
        carModelManagementService.updateFuelTank(map);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

}
